<style>
	.block-mb15{
		display: inline-block;margin-bottom: 15px;
	}
</style>
<div class="container-fluid" style="padding: 20px 10px 0px 10px">
	<div class="row-fluid">
		<div class="well">
		    <ul class="nav nav-tabs">
		      <li class="active"><b>入库信息</b></li>
		    </ul>
		    <div id="myTabContent" class="tab-content">
				<div class="tab-pane active in" id="home">
					<form id="formid" action="/drug/addDrug" method="post">
						<span class="block-mb15">药品：
								<select name="drug_id" id="drug_id" style="margin-left:24px;width:215px;" <?=$is_update?'disabled':''?>>
									<option value="">请选择药品</option>
									<?php if($drug){foreach($drug as $k=>$v){?>
									<option value="<?=$v['id']?>"  <?php if($getData['drug_id'] == $v['id']){echo 'selected';}?>><?=$v['drug_name']?></option>
									<?php }}?>
								</select>
						</span>
						<span style="display:inline-block;margin-left:10px;">种类：<input type="text" readonly value="<?=$getData['type']?>" placeholder="种类" style="width:200px;margin-left: 24px;" name="type" class="type">
						</span><br/>
						<span class="block-mb15">规格型号：<input type="text" readonly value="<?=$getData['drug_size']?>" placeholder="规格型号" style="width:200px" name="drug_size" class="drug_size">
						</span>
						<span style="margin-left:10px;">单位：<input type="text" readonly value="<?=$getData['drug_unit']?>" placeholder="单位" style="width:200px;margin-left: 24px;" name="drug_unit" class="drug_unit">
						</span><br/>
						<span class="block-mb15">药品编号：<input type="text" readonly value="<?=$getData['drug_no']?>" placeholder="规格型号" style="width:200px" name="drug_no" class="drug_no">
						</span>
						<span style="margin-left:10px;">所在仓库：
								<select name="warehouse" id="warehouse" style="margin-left:-5px;width:212px;">
									<?php if($warehouse){foreach($warehouse as $k=>$v){?>
									<option value="<?=$v['warehouse_id']?>" <?php if($getData['warehouse'] == $v['warehouse_id']){echo 'selected';}?>><?=$v['warehouse_name']?></option>
									<?php }}?>
								</select>
						</span><br/>
						<span class="block-mb15">入库数量：<input type="text" value="<?=$getData['in_stock']?>" placeholder="入库数量" style="width:197px" name="in_stock" class="in_stock">
						</span>
						<span class="block-mb15" style="margin-left:10px;">入库人：<input type="text" value="<?=$getData['storage_name']?>" placeholder="入库人" style="width:200px;margin-left: 14px;" name="storage_name" class="storage_name">
						</span><br/>
						<span class="block-mb15" style="margin-left:30px;">备注：<textarea id="textarea" style="width:495px;height:100px;margin-top:-15px;margin-left: 40px;resize: none" name="remark"><?=htmlspecialchars_decode($getData['remark'])?></textarea></span>
						<input type="hidden" value="<?=$getData['id']?>" name="id">
						<input type="hidden" value="1" name="dosubmit" />
					</form>
				</div>
				<div class="btn-toolbar">
				    <button class="btn btn-primary" id="btn-save" style="margin:18px 0 0 70px"><i class="icon-save"></i> 保存</button>
				  <div class="btn-group">
				  </div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
$(function(){
	$('#btn-save').click(function(){
	    var drug_id = $('#drug_id option:selected').val();
	    var warehouse = $('#warehouse option:selected').val();
	    var in_stock = $('input[name=in_stock]').val();
		if(in_stock == '0'){
		    showmsg('入库数量必须大于0');
		    return false;
		}
		if(!drug_id){
            showmsg('请选择药品');
            return false;
		}else if($('input[name="type"]').val() == ''){
			showmsg('药品种类不能为空！');
            return false;
        }else if($('input[name="drug_no"]').val() == ''){
			showmsg('请填写药品编号');
            return false;
        }else if(!warehouse){
			showmsg('请选择仓库');
			return false;
		}else if($('input[name="drug_size"]').val() == ''){
			showmsg('请填写药品规则型号');
            return false;
        }else if($('input[name="drug_unit"]').val() == ''){
			showmsg('请填写药品单位');
            return false;
        }else if(!checkNum(in_stock)){
			showmsg('请填写正确的入库数量');
            return false;
        }else if($('input[name="storage_name"]').val() == ''){
			showmsg('请填写入库人');
            return false;
        }else{
			setBtn($('#btn-save'));
			$('#formid').submit();
		}
	});

	$('#drug_id').on('change',function(){
	    var val = $(this).val();
	    if(val == ''){
            $('input[name=type]').val('');
            $('input[name=drug_no]').val('');
            $('input[name=drug_size]').val('');
            $('input[name=drug_unit]').val('');
            $('input[name=in_stock]').val('');
            $('input[name=storage_name]').val('');
	        showmsg('请选择药品');
	        return false;
		}
        $.ajax({
            url: '/drug/getDrugInfo',
            type: 'POST',
            dataType: 'json',
            data: {id: val},
        })
            .done(function(data) {
                if(data.code == '0'){
                    $('input[name=type]').val(data.data.type);
                    $('input[name=drug_no]').val(data.data.drug_no);
                    $('input[name=drug_size]').val(data.data.drug_size);
                    $('input[name=drug_unit]').val(data.data.drug_unit);
				}else{
                    showmsg(data.msg);
				}
            })
            .fail(function() {
                console.log("error");
            })
	});
    $('.setImdBtn').click(function(){
        $('#setImd').selfups();
    });

    function checkNum(num)
    {
        var reg = /^\d+(?=\.{0,1}\d+$|$)/
        if(reg.test(num)) {
            return true;
        }
        return false ;
    }

	$('.in_stock').on('keyup',function(){
		$(this).val($(this).val().replace(/[^\d]/g,''));
	});
})
</script>